package com.lims.util.interceptor;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.dispatcher.FilterDispatcher;

import com.lims.po.admin.Admin;

public class JspFilter implements Filter {

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filter) throws IOException, ServletException {
		HttpServletRequest httpReq =(HttpServletRequest)request;
		  HttpServletResponse httpRes = (HttpServletResponse)response;
		  String reqUrl = httpReq.getServletPath();
		  Admin admin=(Admin) httpReq.getSession().getAttribute("admin");
		  if((reqUrl.contains("admin")||reqUrl.contains("fckeditor"))&&admin==null){   //url格式是....pro/lan时所做的处理。
			  httpRes.sendRedirect("../logoutAction.action");
		  }
		  else{
			  filter.doFilter(request, response);
		  }

	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
